import KoaRouter from 'koa-router';
const Router: any = new KoaRouter();
interface Routes {
    path: string,
    method: string,
    handler: Function,
}
let routes: Array<Routes> | null;
export function controller(prefix: string) {
    return function (target: any) {
        if (routes) {
            routes.forEach(item => {
                Router[item.method](prefix + item.path, (...ctx: any) => item.handler.apply(new target, ctx));
            });
        }
        routes = null;
    };
}
//收集路由
function createRoute(method: string) {
    return (path: string): Function => {
        return (target: any, name: string, descriptor: PropertyDescriptor) => {
            if (!routes) routes = [];
            routes.push({
                path: path,
                method: method,
                handler: descriptor.value
            });
        };
    };
}

export const post = createRoute("post");
export const get = createRoute("get");
export default Router;
//引入放在最后
import '../api/user';


